package com.aos.erp.schools.rest.registerschool;


import com.aos.erp.common.bean.IPageBean;
import com.aos.erp.common.bean.ResultEntity;
import com.aos.erp.schools.model.registerschool.entity.RegisterSchool;
import com.aos.erp.schools.model.registerschool.ro.RegisterSchoolRo;
import com.aos.erp.schools.model.registerschool.ro.UpdateRegisterSchoolRo;
import com.aos.erp.schools.model.registerschool.vo.ListRegisterSchoolVo;
import com.aos.erp.schools.model.registerschool.vo.RegisterSchoolVo;
import com.aos.erp.schools.service.registerschool.RegisterSchoolService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.constraints.NotNull;

/**
 * <p>
 * 报名点 前端控制器
 * </p>
 *
 * @author 杨文博
 * @since 2018-12-02
 */
@Slf4j
@RestController
@RequestMapping("/api/register")
@Api(value="报名点接口",tags={"报名点接口"})
public class RegisterSchoolController {

	@Autowired
	private RegisterSchoolService registerSchoolService;



	@GetMapping("/list")
	@ApiOperation(value = "分页查询")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "pageIndex",value = "分页",dataType ="int",paramType ="query" ),
			@ApiImplicitParam(name = "pageSize",value = "分页",dataType ="int",paramType ="query" ),
			@ApiImplicitParam(name = "name",value = "报名点名称",dataType ="String",paramType ="query" )}
	)
	public ResultEntity<IPageBean<ListRegisterSchoolVo>> queryPageBean(@RequestParam(name = "pageIndex", defaultValue = "1") Integer pageIndex, @RequestParam(name = "pageSize", defaultValue = "20") Integer pageSize, @RequestParam(name = "name",required=false) String name,String currentUserId) throws Exception {
		return ResultEntity.success(registerSchoolService.queryByPage(pageIndex, pageSize,name,currentUserId));
	}





	@ApiOperation(value = "新增报名点", notes = "新增报名点")
	@RequestMapping(value = "/add",method = RequestMethod.POST)
	public ResultEntity addRegister(@Validated RegisterSchoolRo registerSchoolRo) throws Exception {
		int count=registerSchoolService.addRegister(registerSchoolRo);
		return ResultEntity.success();
	}

	@ApiOperation(value = "删除报名点", notes = "删除报名点")
	@RequestMapping(value = "/delete",method = RequestMethod.POST)
	@ApiImplicitParam(name = "id",value = "报名点id",required = true,dataType ="long",paramType ="query" )
	public ResultEntity deleteRegister(@RequestParam  Long id){
		return registerSchoolService.deleteRegister(id);
	}

	/**
	 * 获取报名点信息
	 * @[param id  报名点id
	 * @return
	 */
	@ApiOperation(value = "获取报名点信息", notes = "获取报名点信息")
	@RequestMapping(value = "/info", method = RequestMethod.POST)
	@ApiImplicitParam(name = "id",value = "报名点id",required = true,dataType ="long",paramType ="query" )
	public ResultEntity registerInfo(Long id){
		if(id==null){
			return ResultEntity.failed("参数不能为空");
		}
		return registerSchoolService.registerInfo(id);
	}

	/**
	 * 修改报名点
	 * @[param UpdateDivisionRos  报名点实体
	 * @return
	 */
	@ApiOperation(value = "修改报名点", notes = "修改报名点")
	@RequestMapping(value = "/update",method = RequestMethod.POST)
	public ResultEntity updateRegister( @Validated UpdateRegisterSchoolRo updateRegisterSchoolRo){
		return registerSchoolService.updateRegister(updateRegisterSchoolRo);
	}


}

